//
//  WMMembershipPackageView.swift
//  deWaterMarkingProject
//
//  Created by admin on 2025/9/5.
//

import UIKit

class WMMembershipPackageView: UIView {

    @IBOutlet weak var bacView: UIView!
    @IBOutlet weak var limitOpenImageView: UIImageView!
    @IBOutlet weak var limitOpenLabel: UILabel!
    
    @IBOutlet weak var packageNameLabel: UILabel!
    @IBOutlet weak var amountLabel: UILabel!
    @IBOutlet weak var discountLabel: UILabel!
    @IBOutlet weak var orgPriceLabel: UILabel!
    
    var tapGestureClick: ((_ tag: Int) -> Void)? = nil
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(userTapGestureDetected))
        self.bacView.addGestureRecognizer(tapRecognizer)
    }
    
    var listModel: WMPackageListModel? {
        didSet {
            if let listModel = listModel {
                
                limitOpenImageView.isHidden = !listModel.warn.or(false)
                limitOpenLabel.isHidden = !listModel.warn.or(false)
                packageNameLabel.text = listModel.name.or("")
                amountLabel.text = "\(listModel.money.or(0))"
                discountLabel.text = listModel.attr.or("")
                orgPriceLabel.text = listModel.message.or("")

            }
        }
    }
    
    @objc func userTapGestureDetected(recognizer : UIGestureRecognizer) {
        self.tapGestureClick?(recognizer.view?.tag ?? 0)
    }
}
